package jp.co.mclnet.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jdk.nashorn.internal.objects.annotations.Where;
import jp.co.mclnet.dao.JdbcDaoImpl;

public class KusanoCalc2 {
    public static void main(String[] args) {
        String tableName = "xyz_speed";
        Connection conn = null;
        try {
            conn = DriverManager
                    .getConnection(
                            "jdbc:mysql://localhost:3306/saturday?useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true",
                            "root", "");
            JdbcDaoImpl dao = new JdbcDaoImpl(tableName);
            dao.setConnection(conn);
            Iterator<HashMap<String, Object>> read = dao
                    .read(new HashMap<String, Object>());
            List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
            while (read.hasNext()) {
                list.add(read.next());
            }
            Set<Object> table = new HashSet<Object>();
            List<String> x = new ArrayList<String>();
            List<String> y = new ArrayList<String>();
            List<String> value = new ArrayList<String>();

            for(int i=0;i < list.size();i++){
                x.add((String)list.get(i).get("x"));
                y.add((String)list.get(i).get("y"));
                table.add(list.get(i).get("z"));
                value.add((String)list.get(i).get("value"));
                if(x.size() != 0){
                }
            }

            System.out.println(x);
            System.out.println(y);
            System.out.println(table);
            System.out.println(value);
        } catch (SQLException e) {
            throw new IllegalArgumentException(e);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                    conn = null;
                } catch (SQLException e) {
                    throw new IllegalArgumentException(e);
                }
            }
        }

    }
}
